#include "mhacameraex.h"

//#include "app.h"

HGE *mhaCameraEx::hge = 0;
//CApp *CCamera::App = 0;

mhaCameraEx::mhaCameraEx() {
	hge = hgeCreate(HGE_VERSION);
	//App = (CApp*)hge->System_GetState(HGE_USERDATA);
	Clear();
}

mhaCameraEx::~mhaCameraEx() {
	hge->Release();
}

void mhaCameraEx::Clear(void) {
	//HalfWidth = hge->System_GetState(HGE_SCREENWIDTH) / 2;
	//HalfHeight = hge->System_GetState(HGE_SCREENHEIGHT) / 2;
	dX = hge->System_GetState(HGE_SCREENWIDTH) / 2;
	dY = hge->System_GetState(HGE_SCREENHEIGHT) / 2;
	pos.Set(0, 0);
	scale = 1.f;
}

void mhaCameraEx::SetD(float dx, float dy) {
	dX = dx; dY = dy;
}

void mhaCameraEx::Set(float x, float y, float scale) {
	pos.Set(x, y);
	this->scale = scale;
}

void mhaCameraEx::Reset(void) {
	hge->Gfx_SetTransform();
}

void mhaCameraEx::Apply(void) {
	//hge->Gfx_SetTransform(pos.x, pos.y, HalfWidth-pos.x, HalfHeight-pos.y, 0.f, scale, scale);
	hge->Gfx_SetTransform(pos.x, pos.y, dX-pos.x, dY-pos.y, 0.f, scale, scale);
}

void mhaCameraEx::WorldToScreen(float wx, float wy, float *sx, float *sy) {
	//*sx = HalfWidth + (wx - pos.x) * scale;
	//*sy = HalfHeight + (wy - pos.y) * scale;
	*sx = dX + (wx - pos.x) * scale;
	*sy = dY + (wy - pos.y) * scale;
}

void mhaCameraEx::ScreenToWorld(float sx, float sy, float *wx, float *wy) {
	//*wx = pos.x + (sx - HalfWidth) / scale;
	//*wy = pos.y + (sy - HalfHeight) / scale;
	*wx = pos.x + (sx - dX) / scale;
	*wy = pos.y + (sy - dY) / scale;
}
